<template>
<div>
  <el-card class="box-card mt12" shadow="never">
    <el-row>
      <el-col :span="24">
        <el-table border ref="ground" :data="log.Log.impl.dataList" :size="defaultFormItemSize" @sort-change="log.Log.impl.onSortChange" header-cell-class-name="table-header-gray" highlight-current-row @current-change="log.Log.impl.currentRowChange">
          <el-table-column label="昵称" prop="nickName" width="200" show-overflow-tooltip></el-table-column>
          <el-table-column label="阵地名称" prop="groundName" show-overflow-tooltip></el-table-column>
          <el-table-column label="阵地类型" prop="groundType" width="150">
            <template slot-scope="scope">
              <span>{{getgroundTypeName(scope.row)}}</span>
            </template>
          </el-table-column>
          <el-table-column label="打卡时间" prop="createTime" show-overflow-tooltip></el-table-column>
        </el-table>
        <el-row type="flex" justify="end" style="margin-top: 10px;">
          <el-pagination :total="log.Log.impl.totalCount" :current-page="log.Log.impl.currentPage" :page-size="log.Log.impl.pageSize" :page-sizes="[10, 20, 50, 100]" layout="total, prev, pager, next, sizes"
            @current-change="log.Log.impl.onCurrentPageChange" @size-change="log.Log.impl.onPageSizeChange">
          </el-pagination>
        </el-row>
      </el-col>
    </el-row>
  </el-card>

</div>
</template>
<script>
import {
  TableWidget
} from '@/utils/widget.js';
import {
  GroundController
} from '@/api';
import qs from "qs"
export default {
  name: "",
  props: {
    groundId: {
      type: String,
      default: ''
    },
    groundTypeList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      log: {
        formFilter: {},
        Log: {
          impl: new TableWidget(this.loadData, true, true, true, 'createTime', 0)
        },
        isInit: false
      },
    }
  },
  methods: {
    refreshLog(reloadData = false) {
      if (reloadData) {
        this.log.Log.impl.refreshTable(true, 1);
      } else {
        this.log.Log.impl.refreshTable();
      }
      if (!this.log.isInit) {
        // 初始化下拉数据
      }
      this.log.isInit = true;
    },
    loadData(params) {
      if (params == null) params = {};
      params = {
        ...params
      }
      params.footprint = this.log.formFilter;
      params.footprint.groundId = this.groundId
      return new Promise((resolve, reject) => {
        GroundController.getLog(this, params).then(res => {
          resolve({
            dataList: res.data.dataList,
            totalCount: Number(res.data.totalCount)
          });
        }).catch(e => {
          reject(e);
        });
      });
    },
    getgroundTypeName(row) {
      let me = this;
      let arr = me.groundTypeList.filter(x => x.id == row.groundType);
      return arr[0].name
    }
  },
  mounted() {
    this.refreshLog();
  }
}
</script>
<style lang="scss" scoped>
</style>
